package com.gagakuai.bpm.config.events;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


@ComponentScan
@Configuration
public class ApplicationEventMulticasterConfig {


    @Bean
    public ApplicationEventMulticaster applicationEventMulticaster(){
        SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new SimpleApplicationEventMulticaster();
        simpleApplicationEventMulticaster.setTaskExecutor(executorService());
        return simpleApplicationEventMulticaster;
    }

    @Bean
    public ExecutorService executorService() {
        return new ThreadPoolExecutor(
                5,
                150,
                1500,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>()
        );
    }

}
